package com.rockxin.cat.activity;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.rockxin.cat.R;
import com.rockxin.cat.adapter.MyBankCardAdapter;
import com.rockxin.cat.base.BaseActivity;
import com.rockxin.cat.base.Constant;
import com.rockxin.cat.base.User;
import com.rockxin.cat.bean.MyBankCardBean;
import com.rockxin.cat.network.CatNetWork;
import com.rockxin.cat.network.HttpResult;
import com.rockxin.cat.utils.JumpActivityManager;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;
import rx.Subscriber;

/**
 * 我的银行
 */
public class MyBankCardActivity extends BaseActivity {

    @BindView(R.id.back_img)
    ImageView backImg;
    @BindView(R.id.title)
    TextView title;
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    @BindView(R.id.myBankCard)
    TextView myBankCard;

    private MyBankCardActivity myBankCardActivity;
    private MyBankCardAdapter adapter;
    private List<MyBankCardBean> myBankCardBeanList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        myBankCardActivity = this;
    }

    @Override
    protected int setLayout() {
        return R.layout.activity_my_bank_card;
    }

    @Override
    public void initData() {

        myBankCardBeanList = new ArrayList<>();

        title.setText("我的银行卡");
        recyclerView.setHasFixedSize(true);
        recyclerView.setLayoutManager(new LinearLayoutManager(myBankCardActivity, LinearLayoutManager.VERTICAL, false));
        adapter = new MyBankCardAdapter(myBankCardBeanList);
        recyclerView.setAdapter(adapter);

        getNetData();
    }

    private void getNetData() {
        CatNetWork catNetWork = new CatNetWork();
        catNetWork.getMyBankList(User.getInstance().getToken(), "list", new Subscriber<HttpResult<List<MyBankCardBean>>>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {

            }

            @Override
            public void onNext(HttpResult<List<MyBankCardBean>> myBankCardBeanHttpResult) {
                if (myBankCardBeanHttpResult.getStatus() == 1) {
                    final List<MyBankCardBean> data = myBankCardBeanHttpResult.getData();
                    myBankCardBeanList.addAll(data);
                    adapter.notifyDataSetChanged();

                }
            }
        });
    }


    @OnClick({R.id.back_img, R.id.myBankCard})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.back_img:
                finish();
                break;
            case R.id.myBankCard:
                JumpActivityManager.getInstance().jumpAddBankCardActivity(myBankCardActivity);
                break;
        }
    }
}
